/*
 * WageEmployee.java
 *
 * This class inherited from Employee class, is used to store
 * the salary details of a waged employee and display the same
 * using method overloading.
 *
 * 
 */

package com.javacore.day6.maxsoft2;

/**
 * WageEmployee class contains all the details of a waged employee.
 * @author 
 */
public class WageEmployee extends Employee {
    
    /** Creates a new instance of WageEmployee */
    public WageEmployee() {
        
        // Initialize the instance variable with default values
        this("", 0.0, 0, "", 0);
    }
    
    /**
     * Creates a new instance of WageEmployee and stores details
     * in the instance variables.
     * @param name Parameter containing the name of the employee.
     * @param rate Parameter containing the rate per hour.
     * @param hours Parameter containing the number of hours the
     * employee has worked.
     * @param city Parameter containing the name of the city in which the
     * employee worked.
     * @param allowance Parameter containing the allowance amount.
     */
    public WageEmployee(String name, double rate, int hours, String city,
            int allowance) {
        this.name = name;
        this.rate = rate;
        this.hours = hours;
        this.city = city;
        this.allowance = allowance;
    }
    
    /**
     * Method to calculate the overtime payment for employees working in
     * Beijing and London.
     * @param cityAllowance Parameter containing the city allowance amount.
     * @return Returns the calculated overtime payment value.
     */
    double calculateOverTimePay(int cityAllowance) {
        double overtimeAmount = 0;
        
        // Give complete allowance if the city is London
        // else give 90% of the allowance for city Beijing
        // else no allowance
        if(city.equals("London")) {
            overtimeAmount = ((cityAllowance * (this.hours - 10 ))) ;
        } else if(city.equals("Beijing")) {
            overtimeAmount = ((cityAllowance * (this.hours - 10)) * 90 / 100);
        }
        return overtimeAmount;
    }
    
    /**
     * Method to compute overtime pay for an employee not working in
     * Beijing and London.
     * @return Returns the overtime pay.
     */
    double calculateOverTimePay() {
        // If employee is not working in London or Beijing
        // then give 20% of allowance
        return (allowance * hours) * 20 / 100;
    }
    
    /**
     * Method to display the details of waged employees.
     */
    void displayDetails() {
        
        // Variable to store the over time pay
        double overTimePay = 0.0;
        
        // Display employee name
        super.displayDetails();
        
        if(this.hours > 14){
            overTimePay = this.calculateOverTimePay(200);
        } else if(this.hours > 10) {
            overTimePay = this.calculateOverTimePay(100);
        } else {
            overTimePay = this.calculateOverTimePay();
        }
        
        System.out.printf("\nEmployee salary: $%.2f",
                this.rate * this.hours + overTimePay + this.allowance);
    }
    
    /**
     * Instance variable to store rate for one hour.
     */
    double rate;
    
    /**
     * Instance variable to store the employee's working hours.
     */
    int hours;
    
    /**
     * Instance variable to store the name of the city.
     */
    String city;
    
    /**
     * Instance variable to store the city allowance.
     */
    int allowance;
}
